package pres.seanlang.utility.android;

import android.util.Log;

/**
 *  日志二次封装工具类.
 *
 * @author SeanLang
 */
public class ALogUtils {
    /* 日志级别  */
    public static final int VERBOSE = 2;
    public static final int DEBUG = 3;
    public static final int INFO = 4;
    public static final int WARN = 5;
    public static final int ERROR = 6;

    public interface LogOutReceiver {
        void OnReceive(int level, String tag, String text);
    }

    private static LogOutReceiver mOutReceiver = null;

    public static void setOutReceiver(LogOutReceiver receiver) {
        mOutReceiver = receiver;
    }

    private static void print(int level, String tag, String text) {
        if(mOutReceiver != null) {
            mOutReceiver.OnReceive(level, tag, text);
        } else {
            switch (level) {
                case VERBOSE:
                    Log.v(tag, text);
                    break;
                case DEBUG:
                    Log.d(tag, text);
                    break;
                case INFO:
                    Log.i(tag, text);
                    break;
                case WARN:
                    Log.w(tag, text);
                    break;
                case ERROR:
                    Log.e(tag, text);
                    break;
            }
        }
    }

    static public void v(String tag, String text) {
        print(VERBOSE, tag, text);
    }

    static public void d(String tag, String text) {
        print(DEBUG, tag, text);
    }

    static public void i(String tag, String text) {
        print(INFO, tag, text);
    }

    static public void w(String tag, String text) {
        print(WARN, tag, text);
    }

    static public void e(String tag, String text) {
        print(ERROR, tag, text);
    }
}
